package com.tjsinfo.tjsoa.fileExpress.bo;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;

import com.tjsinfo.tjsoa.Dao.IHQLDao;
import com.tjsinfo.tjsoa.Dao.IJDBCDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.fileExpress.dao.ITjsUserEmailDAO;
import com.tjsinfo.tjsoa.fileExpress.vo.TjsUserEmail;

public class TjsUserEmailBo implements ITjsUserEmailBo {
	private IJDBCDao jdbcdao;
	private ITjsUserEmailDAO userEmailDAO;
	private IQbcDao qbcDao;
	private IHQLDao hqldao;
	public IHQLDao getHqldao() {
		return hqldao;
	}

	public void setHqldao(IHQLDao hqldao) {
		this.hqldao = hqldao;
	}

	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.ITjsUserEmailBo#getUserEmailDAO()
	 */
	public ITjsUserEmailDAO getUserEmailDAO() {
		return userEmailDAO;
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.ITjsUserEmailBo#setUserEmailDAO(com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.ITjsUserEmailDAO)
	 */
	public void setUserEmailDAO(ITjsUserEmailDAO userEmailDAO) {
		this.userEmailDAO = userEmailDAO;
	}
	
	public IJDBCDao getJdbcdao() {
		return jdbcdao;
	}

	public void setJdbcdao(IJDBCDao jdbcdao) {
		this.jdbcdao = jdbcdao;
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.ITjsUserEmailBo#save(com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.TjsUserEmail)
	 */
	public void save(TjsUserEmail email) {
		userEmailDAO.save(email);
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.ITjsUserEmailBo#update(com.tjsinfo.tjsoa.fileExpress.Tjs_UserEmail.TjsUserEmail)
	 */
	public void update(TjsUserEmail email) {
		userEmailDAO.update(email);
	}
	
	public TjsUserEmail findById(String id) {
		TjsUserEmail email = userEmailDAO.findById(id);
		return email;
	}
	
	public TjsUserEmail fingByUserId(int id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TjsUserEmail.class);
		DetachedCriteria criteria1 = criteria.createCriteria("tjsUser");
		SimpleExpression a = Restrictions.eq("userId", id);
		criteria1.add(a);
		List list = qbcDao.getCriteria(criteria);
		TjsUserEmail email  = null;
		if(list.size()>0)
		{
			email=(TjsUserEmail) list.iterator().next();
		}
		else
		{
			email = new TjsUserEmail();
			email.setMaxReception(10L);
		}
		return email;
	}
	
	public void updateFileExpress(String id,int maxExpress,long maxReception) {
		String sql = "update t_fileExpress_userSize set maxExpress="+maxExpress+",maxReception="+maxReception+" where UserEmail_id='"+id+"'";
		jdbcdao.executeUpdate(sql);
		jdbcdao.closeStmt();
		jdbcdao.closeConn();
	}
	
	public List upLoadFingByUserIds(Integer[] ids) {
		DetachedCriteria criteria = DetachedCriteria.forClass(TjsUserEmail.class);
		DetachedCriteria criteria1 = criteria.createCriteria("tjsUser");
		Criterion a = Restrictions.in("userId", ids);
		criteria1.add(a);
		List list = qbcDao.getCriteria(criteria);
		return list;
	}
}
